package com.lu.stack.common.model.domain;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import lombok.Data;
import org.springframework.core.env.Environment;

/**
 * @author zhanglu
 * @project lu-cloud-stack
 * @description 系统应用上下文
 * @date 2023/2/1 22:54
 */
@Data
public class ApplicationContextDo {

    public String application;
    private boolean isProd;

    public ApplicationContextDo() {};

    public static ApplicationContextDo load() {
        ApplicationContextDo applicationContext = new ApplicationContextDo();
        applicationContext.setApplication(applicationContext.application());
        applicationContext.setProd(applicationContext.prod());
        return applicationContext;
    }

    /**
     * 当前是否是生产环境
     * @return
     */
    private boolean prod(){
        Environment env = SpringUtil.getBean(Environment.class);
        String active = env.getProperty("spring.profiles.active");
        return ObjectUtil.isNotEmpty(active) && active.equalsIgnoreCase("prod") ? true : false;
    }

    /**
     * 应用名称
     * @return
     */
    private String application(){
        Environment env = SpringUtil.getBean(Environment.class);
        return env.getProperty("spring.application.name");
    }

}
